package com.company.test29;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by v on 16-11-29.
 */
public class Test294 {
    private static Lock lock=new ReentrantLock();

    static class AddSum implements Runnable{
        private static Integer sum=0;

        @Override
        public void run() {
            synchronized (sum){
                sum++;
            }
        }
    }

    public static void main(String[] args) {
        AddSum[] sums=new AddSum[1000];

        for(int i=0;i<sums.length;i++){
            sums[i]=new AddSum();
        }

        ExecutorService executor= Executors.newFixedThreadPool(1000);

        for(int i=0;i<sums.length;i++){
            executor.execute(sums[i]);
        }

        executor.shutdown();

        System.out.println(AddSum.sum);
    }
}
